package com.ddwl.goods.dao;

import org.springframework.util.CollectionUtils;
import com.ddwl.common.dao.TkDao;
import com.ddwl.goods.dto.ItemDiscountDto;
import com.ddwl.goods.dao.mapper.DiscountMapper;
import com.ddwl.goods.dao.model.Discount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * 类DiscountDao.java的实现描述：TODO
 *
 * @author zach
 * @Date :2020-06-08 16:19.
 */
@Repository
public class DiscountDao extends TkDao<DiscountMapper, Discount> {

    @Autowired
    private DiscountMapper discountMapper;

    public List<ItemDiscountDto> getItemDiscountDtos(Set<String> itemIds){
        if(CollectionUtils.isEmpty(itemIds)){
            return null;
        }
        return baseMapper.findItemDiscountNew(itemIds);
    }

    public List<Discount> getItemDiscountByItemId(String itemId){
        Discount discount = new Discount();
        discount.setItemId(itemId);
        return baseMapper.select(discount);
    }


    public void deleteByActivityId(String activityId) {
        discountMapper.deleteByActivityId(activityId);
    }

    public Integer deleteByItemId(String itemId){
        Discount discount = new Discount();
        discount.setItemId(itemId);
        return  baseMapper.delete(discount);

    }
}
